﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MP3Ganizer.BusinessObject.Services.Configuration;

namespace MP3Ganizer.BusinessObject.Services.Test
{
    /// <summary>
    /// Description résumée pour Configuration
    /// </summary>
    [TestClass]
    public class Configuration
    {

        [TestMethod]
        public void TryToSetInfo()
        {
            ConfigurationService service = new ConfigurationService();

            var a = "a";
            service.SetInfo(InfoType.Destination, a);
            object result;
            Assert.IsTrue(service.GetInfo(InfoType.Destination, out result));
            Assert.AreEqual("a", result.ToString());

            service.SetInfo(InfoType.Source, a);
            Assert.IsTrue(service.GetInfo(InfoType.Source, out result));
            Assert.AreEqual("a", result.ToString());


            IEnumerable<string> results;
            service.SetInfo(InfoType.Albums, a);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Albums, out results));
            Assert.AreEqual(string.Join("","a"), string.Join("",results));

            service.SetInfo(InfoType.Artists, a);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Artists, out results));
            Assert.AreEqual(string.Join("", "a"), string.Join("", results));
        }
        [TestMethod]
        public void TryToSetNewValueToReplaceOldValue()
        {
            ConfigurationService service = new ConfigurationService();

            var a = "a";
            var b = "b";
            IEnumerable<string> results;

            service.SetInfo(InfoType.Albums, a);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Albums, out results));
            Assert.AreEqual(string.Join("", "a"), string.Join("", results));
            service.SetInfo(InfoType.Albums, b, a);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Albums, out results));
            Assert.AreEqual(string.Join("", "b"), string.Join("", results));

            service.SetInfo(InfoType.Artists, a);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Artists, out results));
            Assert.AreEqual(string.Join("", "a"), string.Join("", results));
            service.SetInfo(InfoType.Artists, b, a);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Artists, out results));
            Assert.AreEqual(string.Join("", "b"), string.Join("", results));
        }
        [TestMethod]
        public void TryToPersist()
        {
            ConfigurationService service = new ConfigurationService();

            var a = "a";
            service.SetInfo(InfoType.Destination, a);
            service.SetInfo(InfoType.Source, a);
            service.SetInfo(InfoType.Albums, a);
            service.SetInfo(InfoType.Artists, a);

            object result;
            IEnumerable<string> results;


            service.PersistConfig();

            service = new ConfigurationService();

            service.LoadConfig();

            Assert.IsTrue(service.GetInfo(InfoType.Destination, out result));
            Assert.AreEqual("a", result);
            Assert.IsTrue(service.GetInfo(InfoType.Source, out result));
            Assert.AreEqual("a", result);
            Assert.IsTrue(service.GetInfos<string>(InfoType.Albums, out results));
            Assert.AreEqual(string.Join("", "a"), string.Join("", results));
            Assert.IsTrue(service.GetInfos<string>(InfoType.Artists, out results));
            Assert.AreEqual(string.Join("", "a"), string.Join("", results));

        }
    }
}
